package frist50;

import org.junit.jupiter.api.Test;

import java.util.Stack;

public class T0020 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            switch (c){
                case '(':
                    stack.push(')');
                    break;
                case '[':
                    stack.push(']');
                    break;
                case '{':
                    stack.push('}');
                    break;
                default:
                    if (stack.isEmpty())return false;
                    if(c!=stack.pop())return false;
            }
        }
        return stack.isEmpty();
    }
    @Test
    public void test() {
        System.out.println(isValid("()[{}]]"));
    }
}
